#
#  Generated from genmsg/cmake/generator.cmake.in
#
#Make sure we can find buildspace generated messages
include_directories(${CMAKE_BINARY_DIR}/gen/@GENERATOR@)

if(gen@GENERATOR@_SOURCE_DIR)
  find_program_required(gen@GENERATOR@_BIN gen_@GENERATOR@.py PATHS ${gen@GENERATOR@_SOURCE_DIR}/scripts)
  set(gen@GENERATOR@_TEMPLATE_DIR ${gen@GENERATOR@_SOURCE_DIR}/scripts CACHE PATH "template dir")
else()
  find_program_required(gen@GENERATOR@_BIN gen_@GENERATOR@.py)
  set(gen@GENERATOR@_TEMPLATE_DIR @CMAKE_INSTALL_PREFIX@/share/gen@GENERATOR@ CACHE PATH "template dir")
endif()

# Generate .msg->${GENERATOR_FILEEXT} for @GENERATOR@
# The generated ${GENERATOR_FILEEXT} files should be added ALL_GEN_OUTPUT_FILES_@GENERATOR@
macro(_generate_msg_@GENERATOR@ ARG_PKG ARG_MSG ARG_IFLAGS ARG_MSG_DEPS ARG_GEN_OUTPUT_DIR)

  #Create input and output filenames
  get_filename_component(MSG_NAME ${ARG_MSG} NAME)
  get_filename_component(MSG_SHORT_NAME ${ARG_MSG} NAME_WE)

  set(MSG_GENERATED_NAME ${MSG_SHORT_NAME}@GENERATOR_FILEEXT@)
  set(GEN_OUTPUT_FILE ${ARG_GEN_OUTPUT_DIR}/${MSG_GENERATED_NAME})

  assert(CATKIN_ENV)
  add_custom_command(OUTPUT ${GEN_OUTPUT_FILE}
    DEPENDS ${gen@GENERATOR@_BIN} ${ARG_MSG} ${ARG_MSG_DEPS}
    ${gen@GENERATOR@_TEMPLATE_DIR}/msg@GENERATOR_FILEEXT@.template
    ${gen@GENERATOR@_TEMPLATE_DIR}/srv@GENERATOR_FILEEXT@.template
    COMMAND ${CATKIN_ENV} ${gen@GENERATOR@_BIN} ${ARG_MSG}
    ${ARG_IFLAGS}
    -p ${ARG_PKG}
    -o ${ARG_GEN_OUTPUT_DIR}
    -e ${gen@GENERATOR@_TEMPLATE_DIR}
    COMMENT "Generating @GENERATOR_PRETTY@ code from ${ARG_PKG}/${MSG_NAME}"
    )

  list(APPEND ALL_GEN_OUTPUT_FILES_@GENERATOR@ ${GEN_OUTPUT_FILE})
  install(FILES ${GEN_OUTPUT_FILE} DESTINATION share/@GENERATOR@/${ARG_PKG})
endmacro()

#gen@GENERATOR@ uses the same program to generate srv and msg files, so call the same macro
macro(_generate_srv_@GENERATOR@ ARG_PKG ARG_SRV ARG_IFLAGS ARG_MSG_DEPS ARG_GEN_OUTPUT_DIR)
  _generate_msg_@GENERATOR@(${ARG_PKG} ${ARG_SRV} "${ARG_IFLAGS}" "${ARG_MSG_DEPS}" ${ARG_GEN_OUTPUT_DIR})
endmacro()

macro(_generate_module_@GENERATOR@)
  # the macros, they do nothing
endmacro()

set(gen@GENERATOR@_INSTALL_DIR @GENERATOR_INSTALL_DIR@)